﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BreukADO
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void leerlingBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.leerlingBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.breukADODataSet1);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'breukADODataSet1.Leerling' table. You can move, or remove it, as needed.
            this.leerlingTableAdapter.Fill(this.breukADODataSet1.Leerling);
            VulCmbKlassen();
        }

        private void VulCmbKlassen()
        {
            cmbKlassen.Items.Add("Alle");
            try
            {
                DataTable dt = leerlingTableAdapter.GetUniekeKlassen();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    cmbKlassen.Items.Add(dt.Rows[i]["klas"].ToString());
                }
                cmbKlassen.SelectedIndex = 0;
            } catch(Exception){};
        }

        private void cmbKlassen_SelectedIndexChanged(object sender, EventArgs e)
        {
            string klas = cmbKlassen.SelectedItem.ToString();
            if (klas.Equals("Alle")) leerlingBindingSource.RemoveFilter();
            else leerlingBindingSource.Filter = "klas = '" + klas + "'";
        } 
    }
}
